package com.zsix.system.strategy.processVariables;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class ProcessVarContext {
    /**
     * 设置流程参数策略对象
     */
    private final List<ProcessVariableStrategy> processVariablesList;
    /**
     * 构造函数
     * @param jumpStrategies
     */
    public ProcessVarContext(List<ProcessVariableStrategy> jumpStrategies){
        this.processVariablesList=jumpStrategies;
    }

    /**
     * server容器
     */
    private Map<String, ProcessVariableStrategy> processVariablesMap=new HashMap<>();

    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        processVariablesMap=processVariablesList.stream()
                .collect(Collectors.toMap(ProcessVariableStrategy::getType, o->o));
    }

    /**
     * 获取服务对象
     * @param serviceType
     * @return
     */
    public ProcessVariableStrategy getService(String serviceType){
        return processVariablesMap.get(serviceType);
    }
}
